// $codepro.audit.disable
package edu.gatech.team404.junit;

import java.util.List;

import edu.gatech.team404.Account;
import edu.gatech.team404.AccountType;
import edu.gatech.team404.Team;
import edu.gatech.team404.dal.AccountDAL;
import edu.gatech.team404.dal.IDatabase;
import edu.gatech.team404.dal.TeamDAL;
import junit.framework.TestCase;

public class TeamDALTest extends TestCase{
	Account apple1;
	Account apple2;
	Account apple3;
	
	Account bear1;
	Account bear2;
	Account bear3;
	
	String labID;
	String teamID1;
	String teamID2;
	
	Team team1;
	Team team2;
	
	TeamDAL dal;
	
	protected void setUp() throws Exception 
	{
		super.setUp();
		
		apple1 = new Account ("apple1", "apple1", "Apple 1", "apple1@gatech.edu", AccountType.STUDENT);
		apple2 = new Account ("apple2", "apple2", "Apple 2", "apple2@gatech.edu", AccountType.STUDENT);
		apple3 = new Account ("apple3", "apple3", "Apple 3", "apple3@gatech.edu", AccountType.STUDENT);
		
		bear1 = new Account ("bear1", "bear1", "Bear 1", "bear1@gatech.edu", AccountType.STUDENT);
		bear2 = new Account ("bear2", "bear2", "Bear 2", "bear2@gatech.edu", AccountType.STUDENT);
		bear3 = new Account ("bear3", "bear3", "Bear 3", "bear3@gatech.edu", AccountType.STUDENT);
		
		labID = "LAB1";
		team1 = new Team (labID, null, "Team Apple");
		team1.addMember(apple1);
		team1.addMember(apple2);
		team1.addMember(apple3);
		teamID1 = team1.getTeamID();
		
		team2 = new Team (labID, null, "Team Bear");
		team2.addMember(bear1);
		team2.addMember(bear2);
		team2.addMember(bear3);
		teamID2 = team2.getTeamID();
		
		dal = new TeamDAL();
		
		AccountDAL aDal = new AccountDAL();
		aDal.addAccount(apple1);
		aDal.addAccount(apple2);
		aDal.addAccount(apple3);
		
		aDal.addAccount(bear1);
		aDal.addAccount(bear2);
		aDal.addAccount(bear3);
	}
	
	public void testClearTable () {
		IDatabase db = new IDatabase();
		db.clearTable("TeamTable");
		db.clearTable("TeamIDTable");
	}
	
	public void testCreateTeam () {
		dal.createTeam(team1);
		assertEquals ("apple1", team1.getMembers().get(0).getUsername());
		
		dal.createTeam(team2);
		assertEquals ("bear1", team2.getMembers().get(0).getUsername());
	}
	
	public void testGetTeamById() {
		Team team = dal.getTeamById(teamID1);
		assertEquals ("apple1", team.getMembers().get(0).getUsername());
		
		team = dal.getTeamById(teamID2);
		assertEquals ("bear1", team.getMembers().get(0).getUsername());
	}
	
	public void testGetTeam() {
		Team team = dal.getTeam(labID, teamID1, "Team Apple");
		assertEquals ("apple1", team.getMembers().get(0).getUsername());
		
		team = dal.getTeam(labID, teamID2, "Team Bear");
		assertEquals ("bear1", team.getMembers().get(0).getUsername());
	}
	
	public void testGetTeamByName() {
		Team team = dal.getTeamByName(labID, "Team Apple");
		assertEquals ("apple1", team.getMembers().get(0).getUsername());
		
		team = dal.getTeamByName(labID, "Team Bear");
		assertEquals ("bear1", team.getMembers().get(0).getUsername());
	}
	
	public void testGetTeamsInLab() {
		List<Team> teams = dal.getTeamsInLab(labID);
		assertEquals ("Team Apple", teams.get(0).getName());
		assertEquals ("Team Bear", teams.get(1).getName());
	}
	
	public void testUpdateTeam() {
		team1.setName("Team Awesome Apple");
		dal.updateTeam(team1);
		assertEquals ("Team Awesome Apple", dal.getTeamById(teamID1).getName());
	}
	
	public void testRemoveTeam() {
		dal.removeTeam(teamID2);
		assertNull (dal.getTeamById(teamID2));
	}
}
